/**
 * @fileoverview
 * TODO doc me
 */


// Shortcuts
var log = YAHOO.log;
var assert = YAHOO.util.Assert;


// ************************************************************
// MODULE TESTS
// ************************************************************


/**
 * TODO declare the class
 */
flyui.flyted.Service.ModuleTests = function(){};


/** 
 * Test that the contents of the flyui.flyted.Service module have been defined.
 */
flyui.flyted.Service.ModuleTests.testModuleContents = function() {
	
	log("Test \"==== flyui.flyted.Service ModuleTests :: testModuleContents ====\" started.");
	
	assert.isNotUndefined(flyui.flyted.Service, "flyui.flyted.Service is undefined");	
	
	assert.isNotUndefined(flyui.flyted.Image, "flyui.flyted.Image is undefined");
	
};


/**
 * TODO
 */
flyui.flyted.Service.ModuleTestCase = function (){
	var testCase = new YAHOO.tool.TestCase({
		
		name: "=== flyui.flyted.Service ModuleTests ===",
		
		testModuleContents : flyui.flyted.Service.ModuleTests.testModuleContents
		
	});
	
	return testCase;
}


// ************************************************************
// SERVICE TESTS
// ************************************************************


/**
 * TODO
 */
flyui.flyted.Service.ServiceTests = function(){};


/**
 * TODO doc me
 */
flyui.flyted.Service.ServiceTests.testQuery = function(endpointURL, testCase){
	log("Test \"==== flyui.flyted.Service ServiceTests :: testQuery ====\" started.");
		
	var service = new flyui.flyted.Service(endpointURL);
	var query = "ASK { ?s ?p ?o }";
	
	var testOnSuccess = function(responseObject) {
		log("resume test case (success)", "test");
		testCase.resume(function() {
			
			// check status code			
			assert.areEqual(200, responseObject.status);
			
			// try parsing response text as json
			var resultSet = YAHOO.lang.JSON.parse(responseObject.responseText);
			
			// check json content
			assert.isTrue(resultSet["boolean"], "result set not as expected");
		});
	};
	
	var testOnFailure = function(responseObject) {
		log("resume test case (failure)", "test");
		testCase.resume(function() {
			// force failure
			assert.fail("request failed, status "+responseObject.status + " " +responseObject.statusText);
		});
	};
	
	log("initiate request", "test");
	service.query(query, testOnSuccess, testOnFailure);
	
	log("suspend test case (if test runner hangs here, something is wrong)", "test");
	testCase.wait();
};


/**
 * TODO doc me
 * @static
 * @asynchronous
 */
// we no longer use this service
//flyui.flyted.Service.ServiceTests.testFindImagesByFlytedProbeName = function( probeName, expectedImages, endpointURL, testCase ) {
//	
//	log("Test \"==== flyui.flyted.Service ServiceTests :: testFindImagesByFlytedProbeName ("+probeName+") ====\" started.");
//	
//	var service = new flyui.flyted.Service(endpointURL);
//	
//	var testOnSuccess = function( images ) {
//		log("resume test case (success)", "test");
//		testCase.resume(function() {
//
//			flyui.flyted.Service.TestData.compareImageArrays(expectedImages, images);
//			
//		});
//	};
//
//	var testOnFailure = function( response ) {
//		log("resume test case (failure)", "test");
//		testCase.resume(function() {
//			assert.fail("request failed, "+response.status+" "+response.statusText);			
//		});
//	};
//
//	log("initiate request", "test");
//	service.findImagesByFlytedProbeName(probeName, testOnSuccess, testOnFailure);
//	
//	log("suspend test case (if test runner hangs here, something is wrong)", "test");
//	testCase.wait();
//	
//}


/**
 * TODO doc me
 */
flyui.flyted.Service.ServiceTests.testFindImagesByFlybaseGeneID_oneMapping = function( testCase, endpointURL ) {

	log("Test \"==== flyui.flyted.Service ServiceTests :: testFindImagesByFlybaseGeneID_oneMapping ====\" started.");

	var flybaseID = "FBgn0033960"; // maps to/from "CG10151" // N.B. need something that maps to a single flyted gene name
	var service = new flyui.flyted.Service(endpointURL);
	var testData = new flyui.flyted.Service.TestData();
	var expectedImages = [testData.CG10151_in_wt, testData.CG10151_in_comr_and_wt];
	
	var testOnSuccess = function( images ) {
		log("resume test case (success)", "test");
		testCase.resume(function() {
	
			flyui.flyted.Service.TestData.compareImageArrays(expectedImages, images);
		
		});
	};

	var testOnFailure = function( response ) {
		log("resume test case (failure)", "test");
		testCase.resume(function() {
			assert.fail("request failed, "+response.status+" "+response.statusText);			
		});
	};

	log("initiate request", "test");
	service.findImagesByFlybaseGeneID(flybaseID, testOnSuccess, testOnFailure);
	
	log("suspend test case (if test runner hangs here, something is wrong)", "test");
	testCase.wait();

}


/**
 * TODO doc me
 */
flyui.flyted.Service.ServiceTests.testFindImagesByFlybaseGeneID_twoMappings = function( testCase, endpointURL ) {

	log("Test \"==== flyui.flyted.Service ServiceTests :: testFindImagesByFlybaseGeneID_twoMappings ====\" started.");

	// N.B. need something that maps to two flyted gene names
	var flybaseID = "FBgn0052548"; // "FBgn0052548":["CG32548","CG6306"] 

	var service = new flyui.flyted.Service(endpointURL);

	var testOnSuccess = function( images ) {
		log("resume test case (success)", "test");
		testCase.resume(function() {
	
			assert.areEqual(4, images.length, "expect 4 images");
		
		});
	};

	var testOnFailure = function( response ) {
		log("resume test case (failure)", "test");
		testCase.resume(function() {
			assert.fail("request failed, "+response.status+" "+response.statusText);			
		});
	};

	log("initiate request", "test");
	service.findImagesByFlybaseGeneID(flybaseID, testOnSuccess, testOnFailure);
	
	log("suspend test case (if test runner hangs here, something is wrong)", "test");
	testCase.wait();

}

/**
 * TODO doc me
 */
flyui.flyted.Service.ServiceTests.testFindImagesByFlybaseGeneID_noMapping = function( testCase, endpointURL ) {

	log("Test \"==== flyui.flyted.Service ServiceTests :: testFindImagesByFlybaseGeneID_noMapping ====\" started.");

	var flybaseID = "foo"; 
	var service = new flyui.flyted.Service(endpointURL);

	var testOnSuccess = function( images ) {
		assert.areEqual(0, images.length, "expect empty array of images if no mapping");
			
	};

	var testOnFailure = function( response ) {
		assert.fail("this should never be called as request is processed synchronously");			
	};

	log("initiate request", "test");
	service.findImagesByFlybaseGeneID(flybaseID, testOnSuccess, testOnFailure);

	// N.B. this is not asynchronous as expect service to respond immediately if no mappings are available	
};

flyui.flyted.Service.ServiceTests.testB2TMappings = function(testCase, mapping, endpointURL) {
	log("Test \"==== flyui.flyted.Service ServiceTests :: testB2TMappings ====\" started.");
	
     
    var service = new flyui.flyted.Service(endpointURL);
        
	var b = mapping[0];
	var p = mapping[1];
	var img = mapping[2];
		
	var testOnSuccess = function( images ) {
		testCase.resume(function() {
			// TODO
			assert.areEqual(img, images.length, "expect " +img + " images");
			if (images.length > 0){
				var probe = new Array();
				for (var i in images){
					log ("probe of image "+ i + images[i].probe.probeLabels[0]);
					flyui.util.appendIfNotMember(probe, images[i].probe.probeLabels);
				}
				flyui.util.arrayMembersAreEqual(p, probe, "the probes are no expected");
			}
			
		});	
	};

	var testOnFailure = function( response ) {
		testCase.resume(function() {
			assert.fail("this should never be called as request is processed synchronously");
		});			
	};

	log("initiate request", "test");
	service.findImagesByFlybaseGeneID(b, testOnSuccess, testOnFailure);
	
	log("suspend test case (if test runner hangs here, something is wrong)", "test");
	testCase.wait();
     
},

flyui.flyted.Service.ServiceTests.testProbeMappings = function(testCase, mapping, endpointURL) {
	log("Test \"==== flyui.flyted.Service ServiceTests :: testProbeMappings ====\" started.");
       
    var service = new flyui.flyted.Service(endpointURL);

	var b = mapping[0];
	var p = mapping[1];
	var img = mapping[2];
	
	var testOnSuccess = function( images ) {
		//log ("test the probe labels : "+ images.length, "test");
		testCase.resume(function() {
			log ("==== test the number of images for " + b + " ====", "test");
			assert.areEqual(img, images.length, "expect " +img + " images");
			if (images.length > 0){
				var probe = new Array();
				for (var i in images){
					log ("probe of image "+ i + images[i].probe.probeLabels[0]);
					flyui.util.appendIfNotMember(probe, images[i].probe.probeLabels);
				}
				flyui.util.arrayMembersAreEqual(p, probe, "the probes are no expected");
			}
		});	
	};

	var testOnFailure = function( response ) {
		testCase.resume(function() {
			assert.fail("this should never be called as request is processed synchronously");
		});
	}			
	
	log("initiate request", "test");
	service.findImagesByFlybaseGeneID(b, testOnSuccess, testOnFailure);
	
	log("suspend test case (if test runner hangs here, something is wrong)", "test");
	testCase.wait();
		
}

/**
 * TODO doc me
 */
flyui.flyted.Service.ServiceTestCase = function (endpointURL){
	var testCase = new YAHOO.tool.TestCase({
		name: "=== flyui.flyted.Service ServiceTests ===",
		
		testQuery : function() {
			flyui.flyted.Service.ServiceTests.testQuery(endpointURL, this);
		},
		
//		testFindImagesByFlytedProbeName_foo : function() {
//			var probeName = "foo";
//			var testData = new flyui.flyted.Service.TestData();
//			var expectedImages = [];
//			flyui.flyted.Service.ServiceTests.testFindImagesByFlytedProbeName(probeName, expectedImages, endpointURL, this);
//		},
//
//		testFindImagesByFlytedGeneName_Cdc37 : function() {
//			var probeName = "Cdc37";
//			var testData = new flyui.flyted.Service.TestData();
//			var expectedImages = [testData.Cdc37_in_wt];
//			flyui.flyted.Service.ServiceTests.testFindImagesByFlytedProbeName(probeName, expectedImages, endpointURL, this);
//		},
//		
//		testFindImagesByFlytedGeneName_acer : function() {
//			var probeName = "acer";
//			var testData = new flyui.flyted.Service.TestData();
//			var expectedImages = [testData.acer_in_aly, testData.acer_in_wt];
//			flyui.flyted.Service.ServiceTests.testFindImagesByFlytedProbeName(probeName, expectedImages, endpointURL, this);
//		}, 
		
		testFindImagesByFlybaseGeneID_noMapping : function() {
			flyui.flyted.Service.ServiceTests.testFindImagesByFlybaseGeneID_noMapping(this, endpointURL);
		},

		testFindImagesByFlybaseGeneID_oneMapping : function() {
			flyui.flyted.Service.ServiceTests.testFindImagesByFlybaseGeneID_oneMapping(this, endpointURL);
		},

		testFindImagesByFlybaseGeneID_twoMappings : function() {
			flyui.flyted.Service.ServiceTests.testFindImagesByFlybaseGeneID_twoMappings(this, endpointURL);
		},
		
		testB2TMappingsFor_FBgn0010747 : function(){
			var tc = this;
			var mapping = ["FBgn0010747", new Array ("Srp54k"), 5];
			flyui.flyted.Service.ServiceTests.testB2TMappings(tc, mapping, endpointURL);
		},	
		
		testB2TMappingsFor_FBgn0024285 : function(){
			var tc = this;
			var mapping = ["FBgn0024285", new Array ("Srp54"), 2];
			flyui.flyted.Service.ServiceTests.testB2TMappings(tc, mapping, endpointURL);
		},
		
		testB2TMappingsFor_FBgn0004903 : function(){
			var tc = this;
			var mapping = ["FBgn0004903", new Array ("Rb97D"), 3];
			flyui.flyted.Service.ServiceTests.testB2TMappings(tc, mapping, endpointURL);
		},
		
		testB2TMappingsFor_FBgn0015799 : function(){
			var tc = this;
			var mapping = ["FBgn0015799", new Array ("rbf"), 3];
			flyui.flyted.Service.ServiceTests.testB2TMappings(tc, mapping, endpointURL);
		},
		
		testB2TMappingsFor_FBgn0052548 : function(){
			var tc = this;
			var mapping = ["FBgn0052548", new Array ("CG32548","CG6306"), 4];// nice for demo
			flyui.flyted.Service.ServiceTests.testB2TMappings(tc, mapping, endpointURL);
		},	
		
		testB2TMappingsFor_FBgn0042189 : function(){
			var tc = this;
			var mapping = ["FBgn0042189", new Array ("CG17376", "CG18461"), 4];
			flyui.flyted.Service.ServiceTests.testB2TMappings(tc, mapping, endpointURL);
		},	
		
		testB2TMappingsFor_FBgn0052392 : function(){
			var tc = this;
			var mapping = ["FBgn0052392", new Array ("CG10099", "CG32392"), 7];
			flyui.flyted.Service.ServiceTests.testB2TMappings(tc, mapping, endpointURL);
		},
					
		testProbeMappingFor_FBgn0042710 : function(){
			var tc = this;
			var mapping = ["FBgn0042710", ["Hex-t2", "Hex T2"], 4];
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
			 
		testProbeMappingFor_FBgn0031142 : function(){
			var tc = this;
			var mapping = ["FBgn0031142", ["CG10998", "CG10998/r-cup"], 11]; // added assumed typo variant CG10998
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
		
		testProbeMappingFor_FBgn0036924 : function(){
			var tc = this;
			var mapping =  ["FBgn0036924", ["hale", "CG7570/hale"], 11]; // added assumed typo variant hale
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
		
		testProbeMappingFor_FBgn0036925 : function(){
			var tc = this;
			var mapping =  ["FBgn0036925", ["schuy", "CG17736/schuy"], 11]; // added assumed typo variant schuy
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
		testProbeMappingFor_FBgn0038089 : function(){
			var tc = this;
			var mapping =  ["FBgn0038089", ["CG14387", "d-cup"], 5]; // TODO check this one to many mapping is valid//d-cup
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
		
		testProbeMappingFor_FBgn0032859 : function(){
			var tc = this;
			var mapping =   ["FBgn0032859", ["Arc-p34", "ArcP34"], 8]; // ArcP34
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
		
		testProbeMappingFor_FBgn0037462 : function(){
			var tc = this;
			var mapping =   ["FBgn0037462", ["sunz", "CG15179"], 5]; //sunz|CG15179
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
		
		testProbeMappingFor_FBgn0030840 : function(){
			var tc = this;
			var mapping =   ["FBgn0030840", ["CG12993","p-cup"], 7];// TODO p-cup
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
		
		testProbeMappingFor_FBgn0032439 : function(){
			var tc = this;
			var mapping =   ["FBgn0032439", ["ref2", "CG17031"], 5]; //ref2|CG17031)
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
		
		testProbeMappingFor_FBgn0002838 : function(){
			var tc = this;
			var mapping =   ["FBgn0002838", ["ms(3)K81", "CG14251"], 6];//ms\\(3\\)K81|CG14251
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
		
		testProbeMappingFor_FBgn0026781 : function(){
			var tc = this;
			var mapping =   ["FBgn0026781", ["Prosalpha6", "prosalpha1"], 3]; //Prosalpha6
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
		
		testProbeMappingFor_FBgn0050382 : function(){
			var tc = this;
			var mapping =   ["FBgn0050382", ["Prosalpha6", "prosalpha1"], 3]; //Prosalpha6
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		},
		
		testProbeMappingFor_FBgn0013300 : function(){
			var tc = this;
			var mapping = ["FBgn0013300", ["Mst-35Ba", "mst35ba"], 5];
			flyui.flyted.Service.ServiceTests.testProbeMappings(tc, mapping, endpointURL);
		}		
	});
	return testCase;
};


// ************************************************************
// IMAGE TESTS
// ************************************************************


/**
 * @class
 * A collection of tests to test the Image class.
 */
flyui.flyted.Service.ImageTests = function() {};


/**
 * TODO doc me
 */
flyui.flyted.Service.ImageTests.testNewImageFromSPARQLResults = function(){
	
	var testData = new flyui.flyted.Service.TestData();
	
	var images = flyui.flyted.Image.newInstancesFromSPARQLResults(testData.resultSet_CG10998);
	
	assert.areEqual(1, images.length, "one image expected");
	
	var image = images[0];
	
	flyui.flyted.Service.TestData.compareImages(testData.CG10998_in_wt, image);
	
}


/**
 * TODO doc me
 */
flyui.flyted.Service.ImageTests.testNewImagesFromSPARQLResults = function() {

	var testData = new flyui.flyted.Service.TestData();
	
	var images = flyui.flyted.Image.newInstancesFromSPARQLResults(testData.resultSet_acer);
	
	assert.areEqual(2, images.length, "two image expected");
	
	flyui.flyted.Service.TestData.compareImages(testData.acer_in_aly, images[0]);
	flyui.flyted.Service.TestData.compareImages(testData.acer_in_wt, images[1]);
	
}


/**
 * TODO doc me
 */
flyui.flyted.Service.ImageTests.testNewImagesFromEmptySPARQLResults = function() {

	var testData = new flyui.flyted.Service.TestData();
	
	var images = flyui.flyted.Image.newInstancesFromSPARQLResults(testData.resultSet_foo);
	
	assert.areEqual(0, images.length, "no images expected");
}


/**
 * TODO doc me
 */
flyui.flyted.Service.ImageTestCase = function (){
	var testCase = new YAHOO.tool.TestCase({
		name: "=== flyui.flyted.Service ImageTests ===",
		
		testNewImageFromSPARQLResultsForGeneCG10998 :  flyui.flyted.Service.ImageTests.testNewImageFromSPARQLResults,
		
		testNewImagesFromSPARQLResultsForGeneAcer : flyui.flyted.Service.ImageTests.testNewImagesFromSPARQLResults, 
		
		testNewImagesFromEmptySPARQLResultsForGeneFoo : flyui.flyted.Service.ImageTests.testNewImagesFromEmptySPARQLResults
		
	});
	return testCase;
}


// ************************************************************
// TEST DATA
// ************************************************************


/**
 * TODO doc me
 */
flyui.flyted.Service.TestData = function(){
	
	this.FBgn0050382_in_comr = new flyui.flyted.Image();
	this.FBgn0050382_in_comr.fullImageURL = "http://www.fly-ted.org/316/2/comr1.bmp";
	this.FBgn0050382_in_comr.thumbnailURL = "http://www.fly-ted.org/316/thumbnails/2/preview.jpg";
	this.FBgn0050382_in_comr.flytedURL = "http://www.fly-ted.org/316/";
	this.FBgn0050382_in_comr.caption = "prosalpha1 in comr";
	this.FBgn0050382_in_comr.gene = "http://openflydata.org/id/flyted/gene/Prosalpha6";
	this.FBgn0050382_in_comr.probe = new Object();
	this.FBgn0050382_in_comr.probe.probeLabels = ["prosalpha1", "Prosalpha6"];
	
	this.FBgn0050382_in_wt_1 = new flyui.flyted.Image();
	this.FBgn0050382_in_wt_1.fullImageURL = "http://www.fly-ted.org/317/2/wt1.bmp";
	this.FBgn0050382_in_wt_1.thumbnailURL = "http://www.fly-ted.org/317/thumbnails/2/preview.jpg";
	this.FBgn0050382_in_wt_1.flytedURL = "http://www.fly-ted.org/317/";
	this.FBgn0050382_in_wt_1.caption = "prosalpha1 in wt";
	this.FBgn0050382_in_wt_1.gene = "http://openflydata.org/id/flyted/gene/Prosalpha6";
	this.FBgn0050382_in_wt_1.probe = new Object();
	this.FBgn0050382_in_wt_1.probe.probeLabels = ["prosalpha1", "Prosalpha6"];
	
	this.FBgn0050382_in_wt_2 = new flyui.flyted.Image();
	this.FBgn0050382_in_wt_2.fullImageURL = "http://www.fly-ted.org/2218/2/wt01.bmp";
	this.FBgn0050382_in_wt_2.thumbnailURL = "http://www.fly-ted.org/2218/thumbnails/2/preview.jpg";
	this.FBgn0050382_in_wt_2.flytedURL = "http://www.fly-ted.org/2218/";
	this.FBgn0050382_in_wt_2.caption = "Prosalpha6 in wt";
	this.FBgn0050382_in_wt_2.gene = "http://openflydata.org/id/flyted/gene/Prosalpha6";
	this.FBgn0050382_in_wt_2.probe = new Object();
	this.FBgn0050382_in_wt_2.probe.probeLabels = ["prosalpha1", "Prosalpha6"];
		
	this.CG10151_in_wt = new flyui.flyted.Image();
	this.CG10151_in_wt.fullImageURL = "http://www.fly-ted.org/768/2/wt01.bmp";
	this.CG10151_in_wt.thumbnailURL = "http://www.fly-ted.org/768/thumbnails/2/medium.jpg";
	this.CG10151_in_wt.flytedURL = "http://www.fly-ted.org/768/";
	this.CG10151_in_wt.caption = "CG10151 in wt";
	this.CG10151_in_wt.gene = "http://openflydata.org/id/flyted/gene/CG10151";
	this.CG10151_in_wt.probe = new Object();
	
	this.CG10151_in_comr_and_wt = new flyui.flyted.Image();
	this.CG10151_in_comr_and_wt.fullImageURL = "http://www.fly-ted.org/769/2/wtandcomr.bmp";
	this.CG10151_in_comr_and_wt.thumbnailURL = "http://www.fly-ted.org/769/thumbnails/2/medium.jpg";
	this.CG10151_in_comr_and_wt.flytedURL = "http://www.fly-ted.org/769/";
	this.CG10151_in_comr_and_wt.caption = "CG10151 in comr AND wt";
	this.CG10151_in_comr_and_wt.gene = "http://openflydata.org/id/flyted/gene/CG10151";
	this.CG10151_in_comr_and_wt.probe = new Object();
	
	this.CG10998_in_wt = new flyui.flyted.Image();
	this.CG10998_in_wt.fullImageURL = "http://www.fly-ted.org/742/2/wt01.bmp";
	this.CG10998_in_wt.thumbnailURL = "http://www.fly-ted.org/742/thumbnails/2/medium.jpg";
	this.CG10998_in_wt.flytedURL = "http://www.fly-ted.org/742/";
	this.CG10998_in_wt.caption = "CG10998 in wt";
	this.CG10998_in_wt.gene = "http://openflydata.org/id/flyted/gene/CG10998";
	this.CG10151_in_wt.probe = new Object();
	
	this.Cdc37_in_wt = new flyui.flyted.Image();
	this.Cdc37_in_wt.fullImageURL = "http://www.fly-ted.org/2122/2/wt01.bmp";
	this.Cdc37_in_wt.thumbnailURL = "http://www.fly-ted.org/2122/thumbnails/2/medium.jpg";
	this.Cdc37_in_wt.flytedURL = "http://www.fly-ted.org/2122/";
	this.Cdc37_in_wt.caption = "Cdc37 in wt";
	this.Cdc37_in_wt.gene = "http://openflydata.org/id/flyted/gene/Cdc37";
	this.Cdc37_in_wt.probe = new Object();
	this.Cdc37_in_wt.probe.probeLabels = ["Cdc37"];
		
	this.resultSet_CG10998 = {
	  "head": {
	    "vars": [ "fullImageURL" , "thumbnailURL" , "flytedURL" , "caption", "geneName" ]
	  } ,
	  "results": {
	    "bindings": [
	      {
	        "fullImageURL": { "type": "uri" , "value": "http://www.fly-ted.org/742/2/wt01.bmp" } ,
	        "thumbnailURL": { "type": "uri" , "value": "http://www.fly-ted.org/742/thumbnails/2/medium.jpg" } ,
	        "flytedURL": { "type": "uri" , "value": "http://www.fly-ted.org/742/" } ,
	        "caption": { "type": "literal" , "value": "CG10998 in wt" },
	        "gene": { "type": "uri" , "value": "http://openflydata.org/id/flyted/gene/CG10998" }
	      }
	    ]
	  }
	};
	
	this.resultSet_acer = {
	  "head": {
	    "vars": [ "fullImageURL" , "thumbnailURL" , "flytedURL" , "caption", "geneName" ]
	  } ,
	  "results": {
	    "bindings": [
	      {
	        "fullImageURL": { "type": "uri" , "value": "http://www.fly-ted.org/1530/2/acer-aly.jpg" } ,
	        "thumbnailURL": { "type": "uri" , "value": "http://www.fly-ted.org/1530/thumbnails/2/medium.jpg" } ,
	        "flytedURL": { "type": "uri" , "value": "http://www.fly-ted.org/1530/" } ,
	        "caption": { "type": "literal" , "value": "acer in aly" },
	        "gene": { "type": "uri" , "value": "http://openflydata.org/id/flyted/gene/acer" }
	      } ,
	      {
	        "fullImageURL": { "type": "uri" , "value": "http://www.fly-ted.org/1531/2/acer-wt.jpg" } ,
	        "thumbnailURL": { "type": "uri" , "value": "http://www.fly-ted.org/1531/thumbnails/2/medium.jpg" } ,
	        "flytedURL": { "type": "uri" , "value": "http://www.fly-ted.org/1531/" } ,
	        "caption": { "type": "literal" , "value": "acer in wt" },
	        "gene": { "type": "uri" , "value": "http://openflydata.org/id/flyted/gene/acer" }
	      }
	    ]
	  }
	};
	
	this.acer_in_aly = new flyui.flyted.Image();
	this.acer_in_aly.fullImageURL = "http://www.fly-ted.org/1530/2/acer-aly.jpg";
	this.acer_in_aly.thumbnailURL = "http://www.fly-ted.org/1530/thumbnails/2/medium.jpg";
	this.acer_in_aly.flytedURL = "http://www.fly-ted.org/1530/";
	this.acer_in_aly.caption = "acer in aly";
	this.acer_in_aly.gene = "http://openflydata.org/id/flyted/gene/acer";
	this.acer_in_aly.probe = new Object();
	this.acer_in_aly.probe.probeLabels = ['acer'];
	
	this.acer_in_wt = new flyui.flyted.Image();
	this.acer_in_wt.fullImageURL = "http://www.fly-ted.org/1531/2/acer-wt.jpg";
	this.acer_in_wt.thumbnailURL = "http://www.fly-ted.org/1531/thumbnails/2/medium.jpg";
	this.acer_in_wt.flytedURL = "http://www.fly-ted.org/1531/";
	this.acer_in_wt.caption = "acer in wt";
	this.acer_in_wt.gene = "http://openflydata.org/id/flyted/gene/acer";
	this.acer_in_wt.probe = new Object();
	this.acer_in_wt.probe.probeLabels = ['acer'];
	
	
	this.resultSet_foo = {
	  "head": {
	    "vars": [ "fullImageURL" , "thumbnailURL" , "flytedURL" , "caption" ]
	  } ,
	  "results": {
	    "bindings": [
	      
	    ]
	  }
	};
}


/**
 * Compare two image objects.
 * @param {flyui.flyted.Image} expected
 * @param {flyui.flyted.Image} actual
 */
flyui.flyted.Service.TestData.compareImages = function( expected, actual ) {
	log("test flyted full image url", "test");
	assert.areEqual(expected.fullImageURL, actual.fullImageURL, "full image URL not expected");
	
	log("test flyted thumbnail url", "test");
	assert.areEqual(expected.thumbnailURL, actual.thumbnailURL, "thumbnail URL not expected");
	
	log("test url to flyted repository", "test");
	assert.areEqual(expected.flytedURL, actual.flytedURL, "FlyTED URL not expected");
	
	log("test image caption", "test");
	assert.areEqual(expected.caption, actual.caption, "image caption not expected");

	log("test image gene name", "test");
	assert.areEqual(expected.geneName, actual.geneName, "image gene name not expected");
	log ("the actual gene name " + actual.geneName);
	
}


/**
 * TODO doc me
 */
flyui.flyted.Service.TestData.compareImageArrays = function( expecteds, actuals ) {

	log("comparing image arrays", "test");

	assert.areEqual(expecteds.length, actuals.length, "number of images not as expected");
	
	var n = actuals.length;
	for (var i=0; i<n; i++) {
		var expected = expecteds[i];
		var found = false;
		for (var j=0; j<n; j++) {
			var image = actuals[j];
			if (image.fullImageURL == expected.fullImageURL) {
				found = true;
				flyui.flyted.Service.TestData.compareImages(expected, image);
			}
		}
		assert.isTrue(found, "did not find expected image "+expected.fullImageURL);
	}
	
}


// ************************************************************
// TEST SUITE AND RUNNER
// ************************************************************


/** 
 * Construct a YUI test suite for the flyui.flyted.Service module.
 * @param {String} endpointURL URL of service
 * @return a YUI test suite
 * @type YAHOO.tool.TestSuite
 */
flyui.flyted.Service.TestSuite = function(endpointURL) {
	var suite = new YAHOO.tool.TestSuite("== flyui.flyted.Service Test Suite ==");
	suite.add(flyui.flyted.Service.ModuleTestCase());
	suite.add(flyui.flyted.Service.ImageTestCase());
	suite.add(flyui.flyted.Service.ServiceTestCase(endpointURL));
	return suite;
}


/** 
 * Run the flyui.flyted.Service test suite.
 * @param {String} endpointURL URL of service
 */
flyui.flyted.Service.runTests = function(endpointURL) {
	YAHOO.log("flyui.flyted.Service :: running tests", "test");
    YAHOO.tool.TestRunner.clear();
	YAHOO.tool.TestRunner.add(flyui.flyted.Service.TestSuite(endpointURL));
	YAHOO.tool.TestRunner.run();
}
